#include <algorithm>
#include <vector>
#include <string>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>  
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <iostream> 
#include <pthread.h>

using namespace std;

int file_statistics(char * path)
{
    DIR * dir;
    struct dirent * ptr;
    int num_jpg = 0, num_imu = 0;

    if ((dir = opendir(path)) == NULL) {
        perror("open dir error...");
        return -1;
    }

    while ((ptr = readdir(dir)) != NULL) {
        if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0)
          continue;      

        #if 0
        if (NULL != strstr(ptr->d_name,".JPG")) {
            num_jpg++;
        }
        else if (NULL != strstr(ptr->d_name,".IMU")) {
            num_imu++;
        }
        #endif

        string strname = ptr->d_name;

        if (strname.find(".JPG") != std::string::npos) {
            num_jpg++;
        }
        else if (strname.find(".IMU") != std::string::npos) {
            num_imu++;
        }
    }

    cout << "jpg:" << num_jpg << endl;
    cout << "imu:" << num_imu << endl;

    closedir(dir);

    return 0;
}

int main()
{
    char *dir = (char *)"abedfc9e2a2d9e82f68c163a";

    file_statistics(dir);

    return 0;
}

